package net.wanho.advice;

import net.wanho.exception.UnauthorizedException;
import net.wanho.vo.AjaxResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler
    public AjaxResult handleUnauthorizedException(UnauthorizedException e){
        e.printStackTrace();
        return AjaxResult.error(HttpStatus.UNAUTHORIZED.value(),"您没有权限访问，请联系管理员！");
    }

    @ExceptionHandler
    public AjaxResult handleException(Exception e){
        e.printStackTrace();
        return AjaxResult.error(e.getMessage());
    }
}
